package scau.jump.securitytrace.main;

import java.util.List;

import scau.jump.securitytrace.cache.ProductCache;
import scau.jump.securitytrace.listener.LoginFrameListener;
import scau.jump.securitytrace.service.ProductService;
import scau.jump.securitytrace.service.SpringUtils;
import scau.jump.securitytrace.ui.LoginFrame;
import scau.jump.securitytrace.ui.ProductComboBoxModel;

import com.securitytrace.model.Product;

public class Main {
	
	ProductService productService;
	
	public Main(){
		init();
	}
	
	private void init(){
		productService = (ProductService) SpringUtils.getBean("productService");
		List<Product> list = (List<Product>) productService.getList();
		
		String[] productNameArry = new String[list.size()];
		
		for(int index = 0;index < list.size(); index++){
			Product product = (Product) list.get(index);
			productNameArry[index] = product.getName();
			ProductCache.productMap.put(product.getName(), product);
			if(product.getOtherInfo() == null){
				ProductCache.productOtherInfoMap.put(product.getName(),"");
			}else{
				ProductCache.productOtherInfoMap.put(product.getName(),product.getOtherInfo());
			}
		}
		ProductComboBoxModel comboBoxModel = new ProductComboBoxModel();
		comboBoxModel.addElements(productNameArry);
	}
	
	private void start(){
		LoginFrameListener listener = new LoginFrameListener();
		LoginFrame loginFrame = new LoginFrame();
		loginFrame.addLoginButtonActionListener(listener);
		listener.setLoginFrame(loginFrame);
	}

	public static void main(String []args){
		Main mian = new Main();
		mian.start();
	}
}
